import uuid
from Connector.client import res_success, res_err
from service.func.attribute_get import attribute_get


class CmdAttributeGet:
    name = "cmd_attribute_get"
    id = uuid.uuid4()

    def __init__(self, service, Params, Tag, Type):
        self.service = service
        self.params = Params
        self.tag = Tag
        self.type = Type

    async def execute(self):
        attribute = self.params.get("attribute")
        if attribute is None:
            res_err(self.tag, self.type, "attribute is None")
        else:
            path = attribute_get(self.service, attribute)
            await res_success(self.tag, self.type, {
                "DataPath": path
            })
